﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Systemet.Domain;
namespace Systemet
{
    public partial class AccessController
    {
        private UserControl mainView;
        private UserControl sidMeny;
        private User loggedInUser;
        private UserRole userRoleLoggedInUser;
        private static AccessController instance;
        private StreamReader pss;
        private bool kostnadsbudgetUnlocked = true;
        private bool intäktsbudgetUnlocked = true;
        private string connection;
        private string line;

        private AccessController() { }

        private string connectionToDB()
        {
            pss = new StreamReader(@"Kommentarer.txt");
            while ((line = pss.ReadLine()) != null)
            {
                connection = line;
            }
            return connection;
        }

        public static AccessController Instance
        {
            get 
            {
                if (instance == null)
                {
                    instance = new AccessController();
                }
                return instance;
            }
        }

        public User LoggedInUser
        {
            get { return loggedInUser; }
            set { loggedInUser = value; }
        }

        public bool KostnadsBudgetUnlocked
        {
            get { return kostnadsbudgetUnlocked; }
            set { kostnadsbudgetUnlocked = value; }
        }

        public bool IntäktsbudgetUnlocked
        {
            get { return intäktsbudgetUnlocked; }
            set { intäktsbudgetUnlocked = value; }
        }

        public UserRole UserRoleLoggedInUser
        {
            get { return userRoleLoggedInUser; }
            set { userRoleLoggedInUser = value; }
        }

        public string Connection
        {
            get { return connection != null ? connection : connectionToDB(); }
            set { value = connection; }
        }
        
        public UserControl MainView
        {
            get { return mainView; }
            set { mainView = value; }
        }

        public UserControl SidMeny
        {
            get { return sidMeny; }
            set { sidMeny = value; }
        }

        public UserControl ReturnMainView()
        {
            return this.mainView;
        }
    }
}
